<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of model
 *
 * @author abc
 */

namespace application\kontakty;

class homemodel {

    private $database = false;

    public function __construct() {
        $this->database = new \system\database('mysql');
    }

    public function webname() {
        return \system\config::getConfig('webname');
    }

    public function info() {

        return 'Dnes je: ' . date('j. n. Y', time()) . ' | Přihlášen jako: ' . \system\session::get('username');
    }

    public function footer() {
        return 'powered by:<br><strong>php | mysql | html | css</strong>';
    }

    public function sidebar() {
        return '<a href=' . WWW_PATH . '/kontakty/pridat>< přidat</a>';
    }

    public function contents($app, $appaction, $appparams) {
        if ($app == 'kontakty') :
            $this->database->query('SELECT * FROM contacts ORDER BY id DESC');
            $rows = $this->database->resultset();
            dump($rows);
        else :
            throw new \Exception('Nemáte oprávnění prohlížet data!', 763);
        endif;

        return $rows;
    }
//
//    public function existuser($postusername) {
//        $this->database->query('SELECT username FROM users WHERE username = :username LIMIT 1');
//        $this->database->bind(':username', $postusername);
//        $row = $this->database->single();
//
//        if ($row['username'] == $postusername) : return true;
//        else : return false;
//        endif;
//    }
//
//    public function loggeduser($postusername) {
//        $username = \system\session::get('username');
//        $logged = \system\session::get('logged');
//        $safety = \system\session::get('safety');
//
//        if ($username == $postusername AND $logged == true AND $safety == true) : return true;
//        else : return false;
//        endif;
//    }

}
